import tkinter as tk

top = tk.Tk()
top.resizable(False, False)

q1_option = tk.IntVar()
q2_option = tk.IntVar()
q3_option = [tk.BooleanVar(False), tk.BooleanVar(False), tk.BooleanVar(False), tk.BooleanVar(False)]
q4_option = [tk.BooleanVar(False), tk.BooleanVar(False), tk.BooleanVar(False), tk.BooleanVar(False)]

def AddSingleChoiceQuestion(top, question, option_str, option_var):
    question_frame = tk.Frame(top)
    question_frame.pack(side='top', fill='x')
    question = tk.Label(question_frame, text=question, anchor='w')
    question.pack(side='top', fill='x')
    option_frame = tk.Frame(question_frame)
    option_frame.pack(side='top', fill='x')
    
    options = option_str.split(':')

    option_a = tk.Radiobutton(option_frame, text=options[0], variable=option_var, value=1)
    option_a.pack(side='left')
    option_b = tk.Radiobutton(option_frame, text=options[1], variable=option_var, value=2)
    option_b.pack(side='left')
    option_c = tk.Radiobutton(option_frame, text=options[2], variable=option_var, value=3)
    option_c.pack(side='left')
    option_d = tk.Radiobutton(option_frame, text=options[3], variable=option_var, value=4)
    option_d.pack(side='left')

    # return option_var

def AddMultipleChoiceQuestion(top, question, option_str, option_var):
    question_frame = tk.Frame(top)
    question_frame.pack(side='top', fill='x')
    question = tk.Label(question_frame, text=question, anchor='w', width = len(question))
    question.pack(side='top', fill='x')
    option_frame = tk.Frame(question_frame)
    option_frame.pack(side='top', fill='x')

    options = option_str.split(':')

    option_a = tk.Checkbutton(option_frame, text=options[0], variable=option_var[0], offvalue=False, onvalue=True)
    option_a.pack(side='left')
    option_b = tk.Checkbutton(option_frame, text=options[1], variable=option_var[1], offvalue=False, onvalue=True)
    option_b.pack(side='left')
    option_c = tk.Checkbutton(option_frame, text=options[2], variable=option_var[2], offvalue=False, onvalue=True)
    option_c.pack(side='left')
    option_d = tk.Checkbutton(option_frame, text=options[3], variable=option_var[3], offvalue=False, onvalue=True)
    option_d.pack(side='left')



AddSingleChoiceQuestion(top, '问题1: 1 + 1 = ?', '1:2:3:4', q1_option)
AddSingleChoiceQuestion(top, '问题2: 10 - 10 = ?', '10:9:8:7', q2_option)
AddMultipleChoiceQuestion(top, '问题3: 100 * 100 = ?', '1:9:1:2', q3_option)
AddMultipleChoiceQuestion(top, '问题4: 10f00 / 1000 = ?', '100:90:80:70', q4_option)

submit_btn =  tk.Button(top, width=8, text='交卷')
submit_btn.pack()

top.mainloop()